/**
 * @(#)com.pattern.p_02_observer.weather.WeatherSubject
 *
 * Copyright (c) 2014-2018 上海纬视瑞科技有限公司
 *
 * DESC:
 *
 */
package com.pattern.p_02_observer.weather;


import java.util.ArrayList;
import java.util.List;

/**
 * @author fusf
 * @version 1.0  2016/11/7
 */
public class WeatherSubject implements Subject {

    private float temperature;//温度
    private float humidity;//气压
    private float pressure;//湿度

    private List<Observer1> observer1List = new ArrayList<Observer1>();


    @Override
    public void registerObserver(Observer1 o) {
        observer1List.add(o);
    }

    @Override
    public void removeObserver(Observer1 o) {
        if (observer1List.contains(o)) {
            observer1List.remove(o);
        }
    }

    @Override
    public void notifyObservers() {
        for (Observer1 o : observer1List) {
            o.update(getTemperature(),getHumidity(),getPressure());
        }
    }

    public void sendData(float temperature, float humidity, float pressure) {
        this.temperature = temperature;
        this.humidity = humidity;
        this.pressure = pressure;
        this.notifyObservers();
    }

    public float getTemperature() {
        return temperature;
    }

    public void setTemperature(float temperature) {
        this.temperature = temperature;
    }

    public float getHumidity() {
        return humidity;
    }

    public void setHumidity(float humidity) {
        this.humidity = humidity;
    }

    public float getPressure() {
        return pressure;
    }

    public void setPressure(float pressure) {
        this.pressure = pressure;
    }
}
